<?xml version="1.0" encoding="utf-8" ?>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ page import="java.util.*,
						org.apache.catalina.manager.util.SessionUtils,
						com.ophelisis.common.util.DateUtils,
						com.ophelisis.common.util.MenuUtil,
						com.ophelisis.common.util.StringUtil,
						com.ophelisis.common.util.CommonUtils,
						com.ophelisis.common.consts.ConstCode.MenuGNB,
						com.ophelisis.common.consts.ConstPath,
						com.ophelisis.actions.system.*,
						com.ophelisis.persistence.domain.LogoVO,
						com.ophelisis.persistence.domain.MenuAuthVO,
						com.ophelisis.persistence.domain.MenuGroupVO,
						com.ophelisis.persistence.domain.MenuVO"%>
						
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="page" uri="/tld/xdp-page.tld"%>

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><%=ConstPath.siteTitle%></title>
<link href="css/common.css" rel="stylesheet" />
<link href="css/jquery.alerts.css" rel="stylesheet" />
<link href="css/calendar/ui.all.css" rel="stylesheet" />
<link href="css/fullcalendar/theme.css" rel="stylesheet" />
<link href="css/fullcalendar/fullcalendar.css" rel="stylesheet" />
<link href="css/fullcalendar/fullcalendar.print.css" rel="stylesheet" media="print" />
<script src="js/jquery-1.7.2.js"></script>
<script src="js/common.js"></script>
<script src="js/common.status.js"></script>
<script src="js/jquery-ui.min.js"></script>
<script src="js/jquery.alerts.js"></script>
<script src="js/calendar/ui.datepicker.js"></script>
<script src="js/calendar/jquery.ui.datepicker-ko.js"></script>
<script src="js/fullcalendar/fullcalendar-ophelisis.js"></script>
<%
	String _userId = null;
    String _userNm = null;
    String _userLevel = "0";
    List<MenuAuthVO> _menuAuthList = new ArrayList<MenuAuthVO>();
    List<MenuGroupVO> _menuGroupList = new ArrayList<MenuGroupVO>();
    List<MenuVO> _menuList = new ArrayList<MenuVO>();
    String _logoFileName = null;

    if (session != null) {
    	_userId = (String)session.getAttribute("userId");
    	_userNm = (String)session.getAttribute("userNm");
        _userLevel = (String)session.getAttribute("userLevel");
    	_menuAuthList = (List<MenuAuthVO>)session.getAttribute("menuAuthList");
    	_menuGroupList = (List<MenuGroupVO>)session.getAttribute("menuGroupList");
    	_menuList = (List<MenuVO>)session.getAttribute("menuList");
    	_logoFileName = (String)session.getAttribute("logoFileName");
    }
    
    if(_userId == null) {
		session.setAttribute("userUrl", request.getRequestURL());
		%>
		<script>location.href = "login.action";</script>
		<%
    }
    
	String _groupId = (String)request.getAttribute("_groupId");
	String _menuId = (String)request.getAttribute("_menuId");
	
	String sLogoFile = "<img src=\"images/logo_default.png\" class=\"clickable\" onclick=\"javascript:location.href='mainPage.action'\" title=\"기본으로 제공되는 로고입니다.\n로고를 변경하시려면 [ 포탈 관리 > 메인 로고 관리 ] 에서 로고를 등록하여 주십시오.\" />";
	if (_logoFileName != null) {
		sLogoFile = "<img src=\"logoFileDownload.action?fileName=" + _logoFileName + "\" class=\"clickable\" onclick=\"javascript:location.href='mainPage.action'\" />";
	}
%>
<script>
$(document).ready(function() {
    // 페이지 함수 존재 여부
    if (typeof movePage == "undefined") {
    	alert("페이지에 필요한 필수 함수가 존재하지 않습니다.\nmovePage() 함수를 정의하여 주십시오.");
    }
    
    /*
     * gnbCode : _groupId : 상단 메뉴
     * lnbCode : _menuId : 좌단 메뉴
     */
	var gnbCode = "<%=_groupId%>";
	var lnbCode = "<%=_menuId%>";
	var menuId = "";
	var pathUrl;

	$(".leftli").each(function() {
		menuId = $(this).attr("id");
		
		if(menuId == lnbCode) {
			$(this).find("> a").addClass("on");
			pathUrl = $(this).find("> a").text();
		} 
	});

	$(".menu" + gnbCode).addClass("on");
	
	var locationPath = "";
	if (gnbCode == "0") {
		locationPath = "<li>메인화면</li>";
	} else {
		locationPath = "<li>" + $(".menu" + gnbCode).text() + " ></li><li class='tex1'>" + pathUrl + "</li>";
	}
	$(".location ul").append(locationPath);
	   
    initMainSize();
});

$(window).resize(function() {
    initMainSize();
});

function initMainSize() {
    $("#maincontainer").css("height", getGlobalHeight() - 145);
}
</script>
</head>
<body>
<div id="warp" class="subbg">
	<!-- container Start -->
	<div id="container">
		<!-- GNB Start -->
		<div id="gnb">
			<div class="logo">
				<%=sLogoFile%>
			</div>
			<div class="multmenu">
			    <ul>
			        <li class="navitex"><span title="사용자 권한 레벨(<%=_userLevel%>)"><%=_userNm%></span>님이 로그인 하셨습니다.</li>
			        <li><a href="logout.action"><img src="images/btn/logout.gif" /></a></li>
			    </ul>
			</div>
			<div class="topmenu">
				<div class="location">
					<ul>
						<li><img src="images/icon/icon_home.gif" /> &gt;</li>
					</ul>
				</div>
				<div class="navi">
					<ul>
					<%
						List<MenuGNB> constMenuGroupItem = MenuUtil.getMenuGroup();
					
						String umAction = ""; 
						String umDesc = ""; 
						String umDisplay = "";
						String umGrant = "";
						boolean umCheck = false;
						
					    for (MenuGNB mgb: constMenuGroupItem) {
					    	if (Integer.parseInt(_userLevel) >= Integer.parseInt(mgb.getAuth())) {
					    		umAction = "javascript:goMenu('" + MenuUtil.getMenuFirst(mgb.getMenuId(),_userLevel).getGroupId() + "','" + MenuUtil.getMenuFirst(mgb.getMenuId(),_userLevel).getMenuId() + "','','" + mgb.getName() + "','" + MenuUtil.getMenuFirst(mgb.getMenuId(),_userLevel).getAction() + "','2')";
					    		umDesc = mgb.getDescription();
								umDisplay = "";
								umGrant = "";
								umCheck = true;
								%>
								<li class="<%=umDisplay%>" id="<%=mgb.getMenuId()%>"><a class="menu<%=mgb.getMenuId()%> <%=umGrant%>" title="<%=umDesc%>" href="<%=umAction%>"><%=mgb.getName()%></a></li>
								<%
					    	}
						} 

				    	if (_menuGroupList != null) {
					    	for (int i = 0; i < _menuGroupList.size(); i++) {
								umDesc = "[ " + _menuGroupList.get(i).getMenuGroupNm() + " ] 메뉴에 대한 접근 권한이 없습니다.";
					    		umAction = "javascript:alert('" + StringUtil.escapeJavaScript(umDesc) + "')";
								umDisplay = _menuGroupList.get(i).getUseYn().equals("Y") ? "" : "nodisplay";
								umGrant = "off";
								umCheck = false;
								
					    		for (int j = 0; j < _menuList.size(); j++) {
									if (umCheck == false && _menuGroupList.get(i).getMenuGroupId().equals(_menuList.get(j).getMenuGroupId()) && _menuList.get(j).getUseYn().equals("Y")) {
										if (Integer.parseInt(_userLevel) >= 7) {
											umDesc = _menuList.get(j).getMenuDesc();
											umAction = "javascript:goMenu('" + _menuList.get(j).getMenuGroupId() + "','" + _menuList.get(j).getMenuId() + "','" + _menuList.get(j).getMenuType() + "','" + _menuGroupList.get(i).getMenuGroupNm() + "','" + _menuList.get(j).getMenuValue() + "','2')";
											umGrant = "";
											umCheck = true;
										} else {
											for (int k = 0; k < _menuAuthList.size(); k++) {
												if (_menuList.get(j).getMenuId().equals(_menuAuthList.get(k).getMenuId()) && !_menuAuthList.get(k).getMenuAuth().equals("0")) {
													umDesc = _menuList.get(j).getMenuDesc();
													umAction = "javascript:goMenu('" + _menuList.get(j).getMenuGroupId() + "','" + _menuList.get(j).getMenuId() + "','" + _menuList.get(j).getMenuType() + "','" + _menuGroupList.get(i).getMenuGroupNm() + "','" + _menuList.get(j).getMenuValue() + "','" + _menuAuthList.get(k).getMenuAuth() + "')";
													umGrant = "";
													umCheck = true;
												}
											}
										}
									}
					    		}
					    		
					    		%>
					    		<li class="<%=umDisplay%>" id="<%=_menuGroupList.get(i).getMenuGroupId()%>"><a class="menu<%=_menuGroupList.get(i).getMenuGroupId()%> <%=umGrant%>" title="<%=umDesc%>" href="<%=umAction%>"><%=_menuGroupList.get(i).getMenuGroupNm()%></a></li>
					    		<%
							}
				    	}
					%>
					</ul>
				</div>
			</div>
		</div>